/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  							 script_give_skill.h

	$Header: /heroes4/script_give_skill.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( SCRIPT_GIVE_SKILL_H_INCLUDED )
#define SCRIPT_GIVE_SKILL_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "script_action_type.h"
#include "script_expression_type.h"
#include "script_hero_action.h"
#include "script_hero_adjustment_action.h"
#include "script_target_type.h"
#include "script_targeted_expression.h"
#include "sized_int_types.h"
#include "skill.h"

// --------------------------------------------------------------------------
// t_script_give_skill class
// --------------------------------------------------------------------------

class t_script_give_skill
	:	public t_script_hero_action
{
public:
	// Member functions
	virtual void	add_icons(t_basic_dialog* dialog) const;
	t_skill const &	get_skill() const;

	virtual bool	read( std::streambuf& stream, int version );
	virtual bool	read_from_map(
						std::streambuf &	stream,
						int					format_version );
	virtual bool	write( std::streambuf& stream ) const;

private:
	t_skill			m_skill;

	void			do_action(t_hero* hero) const;
};

// --------------------------------------------------------------------------
// t_script_give_skill inline members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline t_skill const & t_script_give_skill::get_skill() const
{
	return m_skill;
}

SPECIALIZE_SCRIPT_ACTION( k_script_action_give_skill, t_script_give_skill );

// --------------------------------------------------------------------------
// t_script_can_give_skill class
// --------------------------------------------------------------------------

class t_script_can_give_skill
	:	public t_script_targeted_boolean_expression< t_script_hero_target >
{
public:
	// Member functions
	virtual t_result	evaluate(t_expression_context_hero const& context) const;
	virtual t_result	evaluate(t_expression_context_town const& context) const;
	virtual t_result	evaluate(t_expression_context_object const& context) const;
	virtual t_result	evaluate(t_expression_context_army const& context) const;
	virtual t_result	evaluate(t_expression_context_global const& context) const;

	t_skill const &		get_skill() const;

	virtual bool		read( std::streambuf& stream, int version );
	virtual bool		read_from_map(
							std::streambuf &	stream,
							int					format_version );
	virtual bool		write( std::streambuf& stream ) const;

private:
	// Data members
	t_skill		m_skill;

	t_result	do_evaluate(t_hero const* hero) const;
};

// --------------------------------------------------------------------------
// t_script_can_give_skill inline members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline t_skill const & t_script_can_give_skill::get_skill() const
{
	return m_skill;
}

SPECIALIZE_SCRIPT_BOOLEAN_EXPRESSION( k_script_boolean_can_give_skill, t_script_can_give_skill );

// --------------------------------------------------------------------------
// t_script_increase_skill class
// --------------------------------------------------------------------------

class t_script_increase_skill
	:	public t_script_hero_adjustment_action < t_uint8 >
{
public:
	// Constructor
	t_script_increase_skill();

	// Member functions
	virtual void	add_icons(t_basic_dialog* dialog) const;
	t_skill_type	get_skill_type() const;
	
	virtual bool	read( std::streambuf& stream, int version );
	virtual bool	read_from_map(
						std::streambuf &	stream,
						int					format_version );
	virtual bool	write( std::streambuf& stream ) const;

private:
	// Data members
	t_skill_type	m_skill_type;

	void			recursive_increase_skill(t_hero* hero, t_skill_type type) const;

	virtual void	make_adjustment(t_adventure_map* map, t_hero* hero) const;
};

// --------------------------------------------------------------------------
// t_script_increase_skill inline members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline t_script_increase_skill::t_script_increase_skill()
	:	m_skill_type( k_skill_none )
{
}

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
inline t_skill_type t_script_increase_skill::get_skill_type() const
{
	return m_skill_type;
}

SPECIALIZE_SCRIPT_ACTION( k_script_action_increase_skill, t_script_increase_skill );

#endif // !defined( SCRIPT_GIVE_SKILL_H_INCLUDED )
